import cv2
import numpy as np

big_img = cv2.imread("./img/big_img.png")
bh, bw, _ = big_img.shape
small_img = cv2.imread("./img/small_img.png")
sh, sw, _ = small_img.shape

# 模板匹配
# matchTemplate(原图，模板图，匹配算法方式)
result = cv2.matchTemplate(big_img, small_img, cv2.TM_SQDIFF)
x = 0
y = 0
# 找出最小的配置值的下标
for i in range(bh - sh):
    for j in range(bw - sw):
        if result[i, j] == np.min(result):
            y = i
            x = j
            break

cv2.rectangle(big_img, (x, y), (x + sw, y + sh), color=(0, 0, 255), thickness=2)
cv2.imshow("big_img", big_img)
cv2.waitKey(0)
